package com.zy.service.bs.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.zy.dao.bs.OrderDao;
import com.zy.entity.enums.StatusEnum;
import com.zy.entity.bs.Order;
import com.zy.pojo.query.bs.OrderQuery;
import com.zy.pojo.vos.common.PageVo;
import com.zy.service.base.impl.BaseServiceImpl;
import com.zy.service.bs.OrderService;
import com.zy.utils.DateUtil;

import java.util.List;

@Service("orderService")
public class OrderServiceImpl extends BaseServiceImpl<Order> implements OrderService {

	@Autowired
	private OrderDao orderDao;

	@Override
	public PageVo pageOrder(OrderQuery orderQuery, Integer start, Integer limit) {
		return new PageVo(start, limit, this.orderDao.countOrder(orderQuery), this.orderDao.listOrder(orderQuery, start, limit));
	}

	@Override
	public void saveOrder(Order order) {
		long time = DateUtil.getTime();
		order.setCreateTime(time);
		order.setModifyTime(time);
		this.orderDao.save(order);
	}
	
	@Override
	public void updateOrder(Order order) {
		order.setModifyTime(DateUtil.getTime());
		this.orderDao.updateByPrimaryKeySelective(order);
	}

	@Override
	public void removeOrder(long id) {
		try {
			this.orderDao.removeByPrimaryKey(id);
		} catch (Exception e) {
			log.info(e.getMessage(),e);
			Order order = new Order();
			order.setId(id);
			order.setModifyTime(DateUtil.getTime());
			this.orderDao.updateByPrimaryKeySelective(order);
		}
	}

	@Override
	public void recover(long id) {
		Order order = new Order();
		order.setId(id);
		order.setModifyTime(DateUtil.getTime());
		this.orderDao.updateByPrimaryKeySelective(order);
	}

	@Override
	public List<Order> getCustomerOrders(OrderQuery orderQuery) {
		return orderDao.getCustomerOrders(orderQuery);
	}

}
